package com.project.core.jwt;

import java.util.Map;

/**
 * 自动设置登录账号信息（暂时不需要，后续增加记住我功能后，可以使用）
 *
 * @version 1.0
 * @since 1.0
 */
public class AuditAware {

    // 后续数据多的话，可以用map
    private static final ThreadLocal<Map<String, Object>> app = new ThreadLocal<>();

    public static Integer userId() {
        if (app.get() == null || app.get().isEmpty()) {
            return null;
        }
        return (Integer) app.get().get(ClaimKey.USER_ID);
    }

    public static String baseFolderId() {
        if (app.get() == null || app.get().isEmpty()) {
            return null;
        }
        return (String) app.get().get(ClaimKey.BASE_FOLDER_ID);
    }

    public static void init(Integer _userId, String _userBaseFolder) {
        if (app.get() == null || app.get().isEmpty()) {
            app.set(Map.of());
        }
        app.set(Map.of(ClaimKey.USER_ID, _userId, ClaimKey.BASE_FOLDER_ID, _userBaseFolder));
    }

    public static void init(Integer _userId) {
        if (app.get() == null || app.get().isEmpty()) {
            app.set(Map.of());
        }
        app.set(Map.of(ClaimKey.USER_ID, _userId));
    }

    public static void init(String _userBaseFolder) {
        if (app.get() == null || app.get().isEmpty()) {
            app.set(Map.of());
        }
        app.set(Map.of(ClaimKey.BASE_FOLDER_ID, _userBaseFolder));
    }
}
